package com.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.dao.NoticesDao;
import com.model.Notices;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class NoticesAction extends ActionSupport implements ModelDriven<Notices>{
	
	private Notices notices = new Notices();

	public Notices getModel() {
		return notices;
	}
	
	public String getNotices() {
		ActionContext.getContext().getSession().put("notices", NoticesDao.getNotices());
		return null;
	}
	
	public String deleteNotices() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("id");
		NoticesDao.deleteNotices(Integer.valueOf(id));
		return showNotices();
	}
	
	public String modifyNotices() {
		return showNotices();
	}
	
	public String showNotices() {
		ActionContext.getContext().put("notices", NoticesDao.getNotices());
		return "show";
	}
	
	public String addNotices() {
		//System.out.println("content:"+notices.getContent());
		if(notices.getStart()!=null && notices.getEnd()!=null && notices.getContent()!=null) {
			NoticesDao.saveNotices(notices);
			//return showNotices();
		}
		return showNotices();
	}
	
	
}
